home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cocktail / front.lha / front / m2c / WriteTok.c < prev    next >
C/C++ Source or Header  |  1992-08-18  |  3KB  |  123 lines

  1. #include "SYSTEM_.h"
  2.  
  3. #ifndef DEFINITION_IO
  4. #include "IO.h"
  5. #endif
  6.  
  7. #ifndef DEFINITION_Strings
  8. #include "Strings.h"
  9. #endif
  10.  
  11. #ifndef DEFINITION_Idents
  12. #include "Idents.h"
  13. #endif
  14.  
  15. #ifndef DEFINITION_TokenTab
  16. #include "TokenTab.h"
  17. #endif
  18.  
  19. #ifndef DEFINITION_WriteTok
  20. #include "WriteTok.h"
  21. #endif
  22.  
  23. WriteTok_tLanguage WriteTok_Language;
  24. struct WriteTok_1 WriteTok_SourceFileName;
  25.  
  26.  
  27.  
  28. void WriteTok_GenWrTo
  29. # ifdef __STDC__
  30. (IO_tFile f)
  31. # else
  32. (f)
  33. IO_tFile f;
  34. # endif
  35. {
  36.   TokenTab_Terminal t;
  37.   Idents_tIdent sym;
  38.   Strings_tString s;
  39.   TokenTab_TokenError error;
  40.   CARDINAL l;
  41.   CHAR del;
  42.  
  43.   {
  44.     TokenTab_Terminal B_1 = TokenTab_MINTerm, B_2 = TokenTab_MAXTerm;
  45.  
  46.     if (B_1 <= B_2)
  47.       for (t = B_1;; t += 1) {
  48.         if (TokenTab_GetTokenType(t) == TokenTab_Term) {
  49.           sym = TokenTab_TokenToSymbol(t, &error);
  50.           Idents_GetString(sym, &s);
  51.           if (WriteTok_Language == WriteTok_Modula2) {
  52.             IO_WriteS(f, (STRING)"      | ", 8L);
  53.             IO_WriteI(f, (LONGINT)t, 0L);
  54.             IO_WriteS(f, (STRING)": Copy (", 8L);
  55.             del = Strings_Char(&s, 1);
  56.             if (del == '"' || del == '\'') {
  57.               Idents_WriteIdent(f, sym);
  58.             } else {
  59.               IO_WriteC(f, '"');
  60.               Idents_WriteIdent(f, sym);
  61.               IO_WriteC(f, '"');
  62.             }
  63.             IO_WriteS(f, (STRING)", Name);", 8L);
  64.             IO_WriteNl(f);
  65.           } else {
  66.             IO_WriteS(f, (STRING)"\"", 1L);
  67.             if (Strings_Char(&s, 1) == '"' || Strings_Char(&s, 1) == '\'') {
  68.               {
  69.                 LONGCARD B_3 = 2, B_4 = Strings_Length(&s) - 1;
  70.  
  71.                 if (B_3 <= B_4)
  72.                   for (l = B_3;; l += 1) {
  73.                     if (Strings_Char(&s, (Strings_tStringIndex)l) == '\\' || Strings_Char(&s, (Strings_tStringIndex)l) == '"') {
  74.                       IO_WriteC(f, '\\');
  75.                     }
  76.                     IO_WriteC(f, Strings_Char(&s, (Strings_tStringIndex)l));
  77.                     if (l >= B_4) break;
  78.                   }
  79.               }
  80.             } else {
  81.               {
  82.                 LONGCARD B_5 = 1, B_6 = Strings_Length(&s);
  83.  
  84.                 if (B_5 <= B_6)
  85.                   for (l = B_5;; l += 1) {
  86.                     if (Strings_Char(&s, (Strings_tStringIndex)l) == '\\' || Strings_Char(&s, (Strings_tStringIndex)l) == '"') {
  87.                       IO_WriteC(f, '\\');
  88.                     }
  89.                     IO_WriteC(f, Strings_Char(&s, (Strings_tStringIndex)l));
  90.                     if (l >= B_6) break;
  91.                   }
  92.               }
  93.             }
  94.             IO_WriteS(f, (STRING)"\",", 2L);
  95.             IO_WriteNl(f);
  96.           }
  97.         } else if (WriteTok_Language == WriteTok_C) {
  98.           IO_WriteS(f, (STRING)"0,", 2L);
  99.           IO_WriteNl(f);
  100.         }
  101.         if (t >= B_2) break;
  102.       }
  103.   }
  104. }
  105.  
  106. void BEGIN_WriteTok()
  107. {
  108.   static BOOLEAN has_been_called = FALSE;
  109.  
  110.   if (!has_been_called) {
  111.     has_been_called = TRUE;
  112.  
  113.     BEGIN_IO();
  114.     BEGIN_IO();
  115.     BEGIN_Strings();
  116.     BEGIN_Idents();
  117.     BEGIN_TokenTab();
  118.  
  119.     WriteTok_Language = WriteTok_Modula2;
  120.     (void)strncpy((char *)WriteTok_SourceFileName.A, " ", sizeof(WriteTok_SourceFileName.A));
  121.   }
  122. }
  123.